/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lolbuilder.mainClasses;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import lolbuilder.Champions.Impl.Caster;
import lolbuilder.Champions.Impl.GenericChamp;
import lolbuilder.Champions.Impl.Jax;
import lolbuilder.Champions.Interf.DummyChamp;
import lolbuilder.build.Build;
import lolbuilder.calculation.*;

/**
 *
 * @author chocoboSan
 */
public class ItemBuildGeneratorFromFile {
    public static void main(String args[]) throws InterruptedException {
        ArrayList<Build> builds=null;
        try {
            ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream("toto.bin"));
            System.out.println("reading file, plz wait this might take a while...");
            builds=(ArrayList<Build>) inputStream.readObject();
            inputStream.close();
        } catch (Exception ex) {
            Logger.getLogger(ItemBuildGeneratorFromFile.class.getName()).log(Level.SEVERE, null, ex);
        }
        Build bestBuildAd=null;
        Build bestBuildAp=null;
        Build bestBuildTankyAd=null;
        Build bestBuildAdLifeSteal=null;
        /*ArrayList<BestBuildCalculationThread> tasks=new ArrayList<BestBuildCalculationThread>();
        tasks.add(new BestBuildCalculationThread());
        tasks.add(new BestBuildCalculationThread());
        tasks.add(new BestBuildCalculationThread());
        tasks.add(new BestBuildCalculationThread());
        int dispoT=4;
        int actual=0;
         **/
       if (bestBuildAd==null) bestBuildAd=builds.get(0);
       if (bestBuildAp==null) bestBuildAp=builds.get(0);
       if (bestBuildTankyAd==null) bestBuildTankyAd=builds.get(0);
       if (bestBuildAdLifeSteal==null) bestBuildAdLifeSteal=builds.get(0);
       BBadLifeStealThread blst;
       BBadThread badt;
       BBapThread bapt;
       BBtadThread btadt;
        //init phase
           
       blst=new BBadLifeStealThread(builds, bestBuildAdLifeSteal);
       blst.start();

       badt=new BBadThread(builds, bestBuildAd);
       badt.start();

       bapt=new BBapThread(builds, bestBuildAp);
       bapt.start();

       btadt=new BBtadThread(builds, bestBuildTankyAd);
       btadt.start();

      badt.join();
      bestBuildAd=badt.bestBuild;
      bapt.join();
      bestBuildAp=bapt.bestBuild;
      blst.join();
      bestBuildAdLifeSteal=blst.bestBuild;
      btadt.join();
      bestBuildTankyAd=btadt.bestBuild;
      
  
        BuildOrderCalculator bo=new BuildOrderCalculator(bestBuildAd);
        bo.start();

        DummyChamp g=new GenericChamp();/*new Jax();*/
        bestBuildAd.applyThisBuild(g);
        g.calculateAllDatas();
        g.printAllDatas();
        System.out.println("best DpsBuild : "+bestBuildAd+"\n\n\n");

        Caster c=new Caster();
        bestBuildAp.applyThisBuild(c);
        c.calculateAllDatas();
        c.printAllDatas();
        System.out.println("best burst : "+bestBuildAp+"\n\n\n");

        g.resetStats();
        bestBuildTankyAd.applyThisBuild(g);
        g.calculateAllDatas();
        g.printAllDatas();
        System.out.println("tanky score : "+ ItemBuildGenerator.scoreCalculation(g.dpsOver100sec, g.timeToDie));
        System.out.println("best tankyAd : "+bestBuildTankyAd+"\n\n\n");

        
        g.resetStats();
        bestBuildAdLifeSteal.applyThisBuild(g);
        g.calculateAllDatas();
        g.printAllDatas();
        System.out.println("best AdLs : "+bestBuildAdLifeSteal+"\n\n\n");

        
        
        
        System.out.println("\n\n\n will now calculate best order for dps");
        try {
            bo.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(ItemBuildGenerator.class.getName()).log(Level.SEVERE, null, ex);
        }
        Build buildOrderedAd=new Build();
        buildOrderedAd.items.addAll(bo.result.items);
        System.out.println("best build ad ordered : "+buildOrderedAd);
        
        
        
        
        bo=new BuildOrderCalculator(bestBuildTankyAd);
        bo.start();
        System.out.println("\n\n\n will now calculate best order for tanky dps");
        try {
            bo.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(ItemBuildGenerator.class.getName()).log(Level.SEVERE, null, ex);
        }
        Build buildOrderedTankyAd=new Build();
        buildOrderedTankyAd.items.addAll(bo.result.items);
        System.out.println("best build Tanky ad ordered : "+buildOrderedTankyAd);
        
        
    }
    
    
    
}
